package com.yixing.tech.wms.statistics;

import com.yixing.tech.common.base.BusinessException;
import com.yixing.tech.wms.statistics.service.IInventoryOperationFlowStatisticsService;
import com.yixing.tech.wms.statistics.service.IInventoryStatisticsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
@Slf4j
public class StatisticsScheduler {

    @Resource
    IInventoryStatisticsService inventoryStatisticsService;

    @Resource
    IInventoryOperationFlowStatisticsService inventoryOperationFlowStatisticsService;

    // 4分钟一次
    @Scheduled(fixedDelay = 4 * 60 * 1000)
    public void syncInventory() {
        try {
            inventoryStatisticsService.syncInventory();
        } catch (BusinessException e) {
            log.error("同步库存统计信息失败: ", e);
        }
    }

    // 3分钟500ms一次
    @Scheduled(fixedDelay = 3 * 60 * 1000 + 500)
    public void syncStockOutOperation() {
        try {
            inventoryOperationFlowStatisticsService.syncStockOutOperation();
        } catch (Exception e) {
            log.error("同步出入库流水信息失败: ", e);
        }
    }
}
